package com.wzdigit.wms.wms.controller.inv.count;

import com.wzdigit.framework.exception.RestStatusException;
import com.wzdigit.framework.model.response.ErrorEntity;
import com.wzdigit.wms.basic.client.Pager;
import com.wzdigit.wms.basic.client.PagerInfo;
import com.wzdigit.wms.basic.client.response.Result;
import com.wzdigit.wms.basic.util.HttpSessionUtil;
import com.wzdigit.wms.wms.constant.WmsWareConstant;
import com.wzdigit.wms.wms.domain.dto.inv.count.InvCountHeaderRequest;
import com.wzdigit.wms.wms.domain.dto.inv.count.InvCountHeaderResponse;
import com.wzdigit.wms.wms.domain.dto.inv.count.InvCountSapDifResponse;
import com.wzdigit.wms.wms.service.inv.count.StockCountService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.util.List;

@RestController
@Api(tags = "盘点单PDA")
@RequestMapping(value = WmsWareConstant.API_VERSION)
public class StockCountController {

    public static final String REQUEST_MODEL = "/stockCount";

    @Autowired
    StockCountService stockCountService;
    /**初盘复盘共用 传入区分标识isFirst
        * @param invCountHeaderRequest
    	* @param pager
    	* @param servletResponse
    	* @param request
        * @return com.wzdigit.wms.basic.client.PagerInfo<java.util.List<com.wzdigit.wms.wms.domain.dto.inv.count.InvCountHeaderResponse>>
        * @author shuaic
        * @date 2021/10/18 15:39
    */
    @ApiOperation(value = "盘点任务分页查询",notes = "盘点任务分页查询")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/listPage")
    public PagerInfo<List<InvCountHeaderResponse>> listPagerInfo(InvCountHeaderRequest invCountHeaderRequest, Pager<?> pager, HttpServletResponse servletResponse,HttpServletRequest request){
        try {
            String loginName = HttpSessionUtil.getLoginName(request);
            return stockCountService.listPage(invCountHeaderRequest,pager,loginName);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }

    @ApiOperation(value = "盘点单信息查询",notes = "盘点单查询")
    @ApiResponses({ @ApiResponse(code = 500, message = "系统出现异常", response = ErrorEntity.class) })
    @GetMapping(value = REQUEST_MODEL + "/getInvCountHeader/{headerId}")
    public InvCountHeaderResponse  getInvCountHeader(@PathVariable("headerId")Integer headerId,  HttpServletResponse servletResponse, HttpServletRequest request){
        try {
            return stockCountService.getInvCountHeader(headerId);
        } catch (RestStatusException e) {
            e.printStackTrace();
            servletResponse.setStatus(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
            throw e;
        }
    }




}
